package org.graduates.webapp.actions.person.json;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.Person;
import org.projects.graduates.domain.Studying;

@Action(results = { @Result(name = "success", type = "json") })
public class GetPersonsStudiesAction extends BaseAction {

	private static final long serialVersionUID = -1713320769625714958L;

	private long pid = 0L;

	private String error;

	private List<Studying> studies = new ArrayList<Studying>();

	public String execute() {
		Person person = null;
		if (0L == pid) {
			person = getCurrentPerson();
		}else{
			person = Person.get(Person.class, pid);
		}


		if (null == person) {
			error = "找不到TA";
			return SUCCESS;
		}

		studies.addAll(Studying.findBy(person));

		return SUCCESS;
	}

	public long getPid() {
		return pid;
	}

	public void setPid(long pid) {
		this.pid = pid;
	}

	public String getError() {
		return error;
	}

	public List<Studying> getStudies() {
		return studies;
	}

}
